package day4.Object;

import java.util.Objects;

/**
 * ClassName：Student
 *
 * @Author：小鱼
 * @Create：2025-08-07 11:29
 */
public class Student {
    private  String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        //boolean flag = false;
        //判断类似是否为Student类
        if (!(o instanceof Student)) {
            System.out.println("对象类型不是Student类");
            return false;
        }
        if (o == this) {
            System.out.println("引用地址相同是一个对象");
            return true;
        }
        //return flag;
        Student so = (Student) o;
        if (name.equals(so.getName()) && (age == so.age)) {
            System.out.println("引用地址不同。但属性值相同");
            return true;

        }
        return false;
    }


    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
